package cate.game.play.skill.passive.hero;

import cate.common.table.d.GDAttr;
import cate.common.table.d.GDSkill;
import cate.game.play.base.TargetFilterParam;
import cate.game.play.base.TargetSelector;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.TimeActionCtx;
import cate.game.play.proce.move.MoveCtx;
import cate.game.play.skill.passive.PassiveHandler;

/**
 * 自身死亡或生命值低于30%时，为除自身以外当前血量最少的3个友方单位附加【圣光】，并提高自身格挡100%2回合
 */
public class 圣光反馈PH extends PassiveHandler {


	private int 血量;

	private int 自身buff;

	private int 队友人数;

	private int 队友buff;


	//血量=3000&自身buff=？？&队友人数=3&队友buff=？？
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		血量 = args.getInt("血量", 0);
		自身buff = args.getInt("自身buff", 0);
		队友人数 = args.getInt("队友人数", 0);
		队友buff = args.getInt("队友buff", 0);
	}

	@Override
	public void onDead(ActionCtx action, Fighter killer) {
		settle(action);
	}

	@Override
	public void onMoveDone(MoveCtx move, TimeActionCtx action) {
		settle(action);
	}

	private boolean settle;

	private void settle(ActionCtx action) {
		if (settle) {
			return;
		}
		if (skill.owner.attr.total().hpCurRate() > 血量) {
			return;
		}
		settle = true;
		skill.owner.buff.tryAddByTid(action, 自身buff);
		TargetFilterParam filterParam = new TargetFilterParam();
		filterParam.scopeSet(GDSkill.Scope.FRIENDS).smallAttrSet(GDAttr.V_HP_LEFT_RATE).targetNumSet(队友人数);
		for (Fighter fighter : TargetSelector.doFind(skill.owner, action.getTeamVs(), filterParam)) {
			fighter.buff.tryAddByTid(action, skill.owner, 队友buff);
		}
	}
}
